<?php

declare(strict_types=1);

namespace App\CustHub\Controller\Permission;

use App\Common\Constants\PermissionTypeConstants;
use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Controller\BaseController;
use App\CustHub\Service\ChMenuService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: 'ch/permission/menu'),ApiAuth,VerifySignature]
class MenuController extends BaseController
{

    #[Inject]
    protected ChMenuService $service;

    /**
     * 前端选择树（不需要权限）.
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('tree')]
    public function tree(): ResponseInterface
    {
        $data = $this->request->all();
        $data['permission_type'] = PermissionTypeConstants::CUST_HUB;
        return $this->success($this->service->getSelectTreeByUser($data));
    }
}